package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.AppActSelfCarInfoBinding;
import com.sgb.kjwl.model.entity.MyCarInfoEntity;
import com.sgb.kjwl.model.entity.self.EnergyTypeEntity;
import com.sgb.kjwl.model.entity.self.TypeChooseEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.AddressHelper;
import com.sgb.kjwl.utils.DefaultUtil;
import com.sgb.kjwl.utils.GlideEngine;
import com.sgb.kjwl.utils.MoneyValueFilter;
import com.sgb.kjwl.utils.PickerHelper;
import com.sgb.kjwl.utils.RangeFocusChangeListener;
import com.sgb.kjwl.utils.VehicleConstant;
import com.sgb.kjwl.view.constant.RequestCode;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.widget.ChoosePictureDialog;
import com.sgb.kjwl.view.widget.transport.AMapDialog;
import com.sgb.kjwl.view.widget.transport.ChooseFunctionPopWindow;
import com.sgb.kjwl.viewmodel.transport.SelfCarInfoViewModel;
import com.sgb.link.entity.AMapAddressEntity;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.ArrayUtil;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.NumberUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

/**
 * @author: 杨畔
 * @date: 2021/10/9 09:59
 * @Description: 自营车辆信息页
 */
public class SelfCarInfoActivity extends BaseActivity<SelfCarInfoViewModel, AppActSelfCarInfoBinding> {
    //车辆no
    private long mNo;
    //车型选择器
    private OptionsPickerView mCarTypePicker;
    //车长选择器
    private OptionsPickerView mCarLenPicker;
    //车牌颜色选择器
    private OptionsPickerView mCarColorPicker;
    private OptionsPickerView mEnergyPicker;
    //
    private final int TYPE_ONE = 0;//保险时间
    private final int TYPE_TWO = 1;//年检时间
    private int mTimeType;//时间类型
    //时间选择
    private TimePickerView mTimePicker;
    private TimePickerView mLastTimePicker;
    //车辆功能选择器
    private ChooseFunctionPopWindow mCarFunPop;
    //二级省市区地址选择器
    private OptionsPickerView mAddressPicker2;
    //三级省市区地址选择器
    private OptionsPickerView mAddressPicker3;

    public static void start(Context context, long no) {
        Intent intent = new Intent(context, SelfCarInfoActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(RouterKey.NO, no);
        context.startActivity(intent);
    }

    @Override
    protected int layoutId() {
        return R.layout.app_act_self_car_info;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(SelfCarInfoViewModel.class);
    }

    @Override
    protected void init() {
        mBinding.include.titleView.setText("车辆信息");
        initTimePicker();
        initAddressPicker();
        initEvent();
        initData();
    }

    private void initTimePicker() {
        mTimePicker = PickerHelper.with(this).getCommonTimeBuild("选择日期", (date, v) -> {
            //设置保存时间信息（保险时间/年检时间）
            if (mTimeType == TYPE_ONE) {
                mViewModel.submitData().setInsuranceTime(date.getTime());
                mBinding.tvVciInsuranceTime.setText(DateUtils.stampToDay5(date.getTime()));
            } else if (mTimeType == TYPE_TWO) {
                mViewModel.submitData().setAnnualInspectionTime(date.getTime());
                mBinding.tvVciAnnualTime.setText(DateUtils.stampToDay5(date.getTime()));
            }
        }).build();
        mLastTimePicker = PickerHelper.with(this).getCommonTimeBuild("选择日期", (date, v) -> {
            //上次保养时间
            mViewModel.submitData().setUpMaintainTime(date.getTime());
            mBinding.tvVciLastMaintainTime.setText(DateUtils.stampToDay5(date.getTime()));
        })
                .setRangDate(null, Calendar.getInstance())
                .build();
    }

    public void initAddressPicker() {
        DialogHelper.showProgressDialog(this, "数据加载中...");
        AddressHelper.getInstance().getAllArea(new AddressHelper.AddressCallBack() {
            @Override
            public void threeData(List<AddressEntity> provinceList, List<List<AddressEntity>> cityList, List<List<List<AddressEntity>>> districtList) {
                super.threeData(provinceList, cityList, districtList);
                //二级选择/当前去向
                mAddressPicker2 = PickerHelper.with(SelfCarInfoActivity.this)
                        .getCommonPicker("请选择位置", provinceList, cityList, (options1, options2, options3, v) -> {
                            AddressEntity province = provinceList.get(options1);
                            AddressEntity city = cityList.get(options1).get(options2);
                            //设置当前去向
                            StringBuilder address = new StringBuilder();
                            if (province != null) {
                                mViewModel.submitData().setIntentionProvinceName(province.getName());
                                mViewModel.submitData().setIntentionProvinceNo(province.getNo());
                                address.append(province.getName());
                            }
                            if (city != null) {
                                mViewModel.submitData().setIntentionCityName(city.getName());
                                mViewModel.submitData().setIntentionCityNo(city.getNo());
                                address.append(city.getName());
                            }
                            mBinding.tvVciCurrentDestination.setText(address.toString());
                        });
                //三级选择/上户地
                mAddressPicker3 = PickerHelper.with(SelfCarInfoActivity.this)
                        .getCommonPicker("请选择位置", provinceList, cityList, districtList, (options1, options2, options3, v) -> {
                            AddressEntity province = provinceList.get(options1);
                            AddressEntity city = cityList.get(options1).get(options2);
                            AddressEntity district = districtList.get(options1).get(options2).get(options3);
                            //设置车辆上户地
                            StringBuilder address = new StringBuilder();
                            if (province != null) {
                                mViewModel.submitData().setCarProvinceName(province.getName());
                                mViewModel.submitData().setCarProvinceNo(province.getNo());
                                address.append(province.getName());
                            }
                            if (city != null) {
                                mViewModel.submitData().setCarCityName(city.getName());
                                mViewModel.submitData().setCarCityNo(city.getNo());
                                address.append(city.getName());
                            }
                            if (district != null) {
                                mViewModel.submitData().setCarDistrictName(district.getName());
                                mViewModel.submitData().setCarDistrictNo(district.getNo());
                                address.append(district.getName());
                            }
                            mBinding.tvVciRegisterAddress.setText(address.toString());
                        });
            }
        });
    }

    private void initEvent() {
        mBinding.include.ivBack.setOnClickListener(this);
        mBinding.setOnClick(this);
        //
        mBinding.etVciWeight.setFilters(new InputFilter[]{new MoneyValueFilter(), new InputFilter.LengthFilter(10)});
        mBinding.etVciWeight.setOnFocusChangeListener(new RangeFocusChangeListener(0.01, 999.99));
        mBinding.etVciHurdleHeight.setFilters(new InputFilter[]{new MoneyValueFilter(), new InputFilter.LengthFilter(10)});
        mBinding.etVciHurdleHeight.setOnFocusChangeListener(new RangeFocusChangeListener(0.01, 999.99));
        mBinding.etVciCarYears.setOnFocusChangeListener(new RangeFocusChangeListener(1, 50));
        //接口回调
        mViewModel.ldCar.observe(this, this::syncInfo);
        mViewModel.ldCarType.observe(this, this::initCarTypePicker);
        mViewModel.ldCarLen.observe(this, this::initCarLenPicker);
        mViewModel.ldColor.observe(this, this::initCarColorPicker);
        mViewModel.ldCarFunc.observe(this, this::initCarFuncPicker);
        mViewModel.ldEnergy.observe(this, this::initCarEnergyPicker);
        //运输证图片
        mViewModel.ldImage.observe(this, url -> {
            mViewModel.submitData().setTransportCertificateMain(url);
            loadTransportImage(url);
        });
    }


    private void initData() {
        mNo = getIntent().getLongExtra(RouterKey.NO, 0);
        mViewModel.getCarDetail(this, mNo);
        mViewModel.getCarTypeList();
        mViewModel.getColorList();
        mViewModel.getCarFunctionList();
        mViewModel.getEnergyList();
    }

    /**
     * 车辆信息
     */
    private void syncInfo(MyCarInfoEntity entity) {
        mBinding.tvVciCarType.setText(DefaultUtil.getString(entity.getCarTypeName()));
        if (!TextUtils.isEmpty(entity.getCarTypeNo())) {
            //获取车型
            mViewModel.getCarLengthList(entity.getCarTypeNo());
        }
        if (!TextUtils.isEmpty(entity.getCarLenNo())) {
            mBinding.llVciCarLen.setVisibility(View.VISIBLE);
            mBinding.tvVciCarLen.setText(DefaultUtil.getString(entity.getCarLenName()));
        }
        if (!TextUtils.isEmpty(entity.getWeight())) {
            mBinding.etVciWeight.setText(NumberUtil.trim0(entity.getWeight()));
        }
        mBinding.tvVciLicensePlateColor.setText(VehicleConstant.getLicensePlateColorStr(entity.getLicensePlateColor()));
        if (entity.getLatitude() != 0 && entity.getLongitude() != 0
                && !TextUtils.isEmpty(entity.getProvinceNo())) {
            if ((entity.getDetailAddress().contains("省") && entity.getDetailAddress().contains("市"))) {
                mBinding.tvVciLocation.setText(entity.getDetailAddress());
            } else {
                mBinding.tvVciLocation.setText(String.format("%s%s%s%s",
                        entity.getProvinceName(),
                        entity.getCityName(),
                        entity.getDistrictName(),
                        entity.getDetailAddress()));
            }
            mBinding.etVciAddress.setVisibility(View.GONE);
            mBinding.etVciAddress.setText(entity.getDetailAddress());
        }
        if (!TextUtils.isEmpty(entity.getCarProvinceName())) {
            mBinding.tvVciRegisterAddress.setText(String.format("%s/%s/%s",
                    entity.getCarProvinceName(),
                    entity.getCarCityName(),
                    entity.getCarDistrictName()));
        }
        if (!TextUtils.isEmpty(entity.getIntentionProvinceName())) {
            mBinding.tvVciCurrentDestination.setText(String.format("%s/%s",
                    entity.getIntentionProvinceName(),
                    entity.getIntentionCityName()));
        }
        if (!NumberUtil.isNullOrZero(entity.getInsuranceTime())) {
            mBinding.tvVciInsuranceTime.setText(DateUtils.stampToDay5(entity.getInsuranceTime()));
        }
        if (!NumberUtil.isNullOrZero(entity.getAnnualInspectionTime())) {
            mBinding.tvVciAnnualTime.setText(DateUtils.stampToDay5(entity.getAnnualInspectionTime()));
        }
        if (!NumberUtil.isNullOrZero(entity.getUpMaintainTime())) {
            mBinding.tvVciLastMaintainTime.setText(DateUtils.stampToDay5(entity.getUpMaintainTime()));
        }
        if (NumberUtil.isNullOrZero(entity.getCarYears())) {
            mBinding.etVciCarYears.setText("");
        } else {
            mBinding.etVciCarYears.setText(NumberUtil.trim0(entity.getCarYears()));
        }
        loadTransportImage(entity.getTransportCertificateMain());
        mBinding.etVciTransportNumber.setText(DefaultUtil.getString(entity.getTransportCertificateNum()));
        if (!NumberUtil.isNullOrZero(NumberUtil.convertToDouble(entity.getHeightHurdle()))) {
            mBinding.etVciHurdleHeight.setText(VehicleConstant.getTrim0Str(entity.getHeightHurdle()));
        }
        mBinding.tvVciIsDump.setText(VehicleConstant.getIsDumpStr(entity.getIsDump()));
        mBinding.tvVciCarFunction.setText(DefaultUtil.getString(entity.getFunctionNos()));

        mBinding.tvOffice.setText(!TextUtils.isEmpty(entity.getImageIssuingAuthority()) ? entity.getImageIssuingAuthority() : "");
        mBinding.tvEnergy.setText(!TextUtils.isEmpty(entity.getImageVehicleEnergyType()) ? entity.getImageVehicleEnergyType() : "");
    }

    private void loadTransportImage(String url) {
        int thumbnail = TextUtils.isEmpty(url) ? R.drawable.img_daoluzhuye : R.drawable.car_info_bg_img;
        Glide.with(this).load(url)
                .apply(new RequestOptions().centerCrop())
                .placeholder(thumbnail)
                .error(thumbnail)
                .into(mBinding.ivVciTransport);
    }

    private void initCarTypePicker(List<GoodsInfoTypeEntity3> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        //车型
        mCarTypePicker = PickerHelper.with(this).getCommonPicker("选择车型", list, (options1, options2, options3, v) -> {
            GoodsInfoTypeEntity3 entity = list.get(options1);
            //保存车型信息
            mViewModel.submitData().setCarTypeNo(entity.getNo());
            mBinding.tvVciCarType.setText(DefaultUtil.getString(entity.getName()));
            //清空车长信息
            mViewModel.submitData().setCarLenNo("");
            mBinding.tvVciCarLen.setText("");
            //获取车型
            mViewModel.getCarLengthList(entity.getNo());
        });
    }

    private void initCarLenPicker(List<GoodsInfoTypeEntity3> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        //展示车长
        mBinding.llVciCarLen.setVisibility(View.VISIBLE);
        //车型
        mCarLenPicker = PickerHelper.with(this).getCommonPicker("选择车长", list, (options1, options2, options3, v) -> {
            GoodsInfoTypeEntity3 entity = list.get(options1);
            //保存车长信息
            mViewModel.submitData().setCarLenNo(entity.getNo());
            mBinding.tvVciCarLen.setText(DefaultUtil.getString(entity.getName()));
        });
    }

    private void initCarEnergyPicker(List<EnergyTypeEntity> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        mEnergyPicker = PickerHelper.with(this).getCommonPicker("选择能源类型", list, ((options1, options2, options3, v) -> {
            EnergyTypeEntity entity = list.get(options1);
            mViewModel.submitData().setImageSourceCode(entity.getNo());
            mBinding.tvEnergy.setText(entity.getName());
        }));
    }

    private void initCarColorPicker(List<GoodsInfoTypeEntity3> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        //车牌颜色
        mCarColorPicker = PickerHelper.with(this).getCommonPicker("选择车牌颜色", list, (options1, options2, options3, v) -> {
            GoodsInfoTypeEntity3 entity = list.get(options1);
            //保存车牌颜色信息
            mViewModel.submitData().setLicensePlateColor(entity.getNo());
            mBinding.tvVciLicensePlateColor.setText(DefaultUtil.getString(entity.getName()));
        });
    }

    private void initCarFuncPicker(List<GoodsInfoTypeEntity3> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        //车辆功能
        mCarFunPop = new ChooseFunctionPopWindow(this, "选择车辆功能");
        mCarFunPop.setOnDismissListener(() -> mBinding.popBg.setVisibility(View.GONE));
        mCarFunPop.setOnResultClick((key1, key2, key3) -> {
            List<TypeChooseEntity> entity = (List<TypeChooseEntity>) key1;
            //保存车辆功能信息
            setCarFunc(entity);
        });
        //
        List<TypeChooseEntity> chooseEntities = new ArrayList<>();
        for (GoodsInfoTypeEntity3 entity : list) {
            TypeChooseEntity entity1 = new TypeChooseEntity();
            entity1.setSelect(false);
            entity1.setName(entity.getName());
            entity1.setNo(entity.getNo());
            chooseEntities.add(entity1);
        }
        mCarFunPop.setData(chooseEntities);
    }

    public void setCarFunc(List<TypeChooseEntity> list) {
        if (ArrayUtil.isNullOrEmpty(list)) {
            return;
        }
        StringBuilder names = new StringBuilder();
        StringBuilder nos = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            TypeChooseEntity entity = list.get(i);
            nos.append(entity.getNo()).append(",");
            names.append(entity.getName()).append(",");
        }
        if (names.length() == 0) {
            mBinding.tvVciCarFunction.setText("");
        } else {
            mBinding.tvVciCarFunction.setText(names.substring(0, names.length() - 1));
        }
        if (nos.length() != 0) {
            mViewModel.submitData().setFunctionNo(nos.substring(0, nos.length() - 1));
        } else {
            mViewModel.submitData().setFunctionNos("");
        }
    }


    @Override
    public void onMultiClick(View v) {
        closeKeybord();
        if (v == mBinding.include.ivBack) {
            finish();
        } else if (v == mBinding.tvVciCarType) {
            if (ArrayUtil.isNotNullAndEmpty(mViewModel.ldCarType.getValue())) {
                mCarTypePicker.show();
            }
        } else if (v == mBinding.tvVciCarLen) {
            if (ArrayUtil.isNotNullAndEmpty(mViewModel.ldCarLen.getValue())) {
                mCarLenPicker.show();
            } else {
                MToast.showLongToast(this, "该车型未关联车长，请重新选择");
            }
        } else if (v == mBinding.tvVciLicensePlateColor) {
            if (ArrayUtil.isNotNullAndEmpty(mViewModel.ldColor.getValue())) {
                mCarColorPicker.show();
            }
        } else if (v == mBinding.tvVciLocation) {
            AMapDialog.launch(this);
        } else if (v == mBinding.tvVciRegisterAddress) {
            //车辆上户地
            if (mAddressPicker3 != null) {
                mAddressPicker3.show();
            }
        } else if (v == mBinding.tvVciCurrentDestination) {
            //当前去向
            if (mAddressPicker2 != null) {
                mAddressPicker2.show();
            }
        } else if (v == mBinding.tvVciInsuranceTime) {
            //保险时间
            mTimeType = TYPE_ONE;
            mTimePicker.show();
        } else if (v == mBinding.tvVciAnnualTime) {
            //年检时间
            mTimeType = TYPE_TWO;
            mTimePicker.show();
        } else if (v == mBinding.tvVciLastMaintainTime) {
            //上次保养时间（仅支持当前日期前的时间
            mLastTimePicker.show();
        } else if (v == mBinding.ivVciTransport) {
            showPictureDialog();
        } else if (v == mBinding.tvVciCarFunction) {
            if (ArrayUtil.isNotNullAndEmpty(mViewModel.ldCarFunc.getValue())) {
                mCarFunPop.showDownPopwindow(mBinding.tvVciCarFunction, false);
                mCarFunPop.setTittle("选择车辆功能");
                mBinding.popBg.setVisibility(View.VISIBLE);
            }
        } else if (v == mBinding.tvVciIsDump) {
            chooseDump();
        } else if (v == mBinding.tvVciSubmit) {
            clearAllFocus();
            submit();
        } else if (v == mBinding.tvEnergy) {
            mEnergyPicker.show();
        }
    }

    /**
     * 提交数据
     */
    private void submit() {
        //载重
        if (mBinding.etVciWeight.getText() != null && !TextUtils.isEmpty(mBinding.etVciWeight.getText())) {
            mViewModel.submitData().setWeight(NumberUtil.trim0(mBinding.etVciWeight.getText().toString()));
        } else {
            MToast.showToast(this, "请输入车辆额定载重");
            return;
        }
        //地址
        if (mBinding.etVciAddress.getText() != null && !TextUtils.isEmpty(mBinding.etVciAddress.getText())) {
            mViewModel.submitData().setDetailAddress(mBinding.etVciAddress.getText().toString());
        } else {
            MToast.showToast(this, "车辆详细地址不能为空");
            return;
        }
        //运输证主页
        if (mBinding.etVciTransportNumber.getText() != null && !TextUtils.isEmpty(mBinding.etVciTransportNumber.getText())) {
            mViewModel.submitData().setTransportCertificateNum(mBinding.etVciTransportNumber.getText().toString());
        } else {
            mViewModel.submitData().setTransportCertificateNum("");
        }
        //栏高
        if (mBinding.etVciHurdleHeight.getText() != null && !TextUtils.isEmpty(mBinding.etVciHurdleHeight.getText())) {
            mViewModel.submitData().setHeightHurdle(NumberUtil.trim0(mBinding.etVciHurdleHeight.getText().toString()));
        } else {
            mViewModel.submitData().setHeightHurdle("");
        }
        //车辆年限
        if (mBinding.etVciCarYears.getText() != null && !TextUtils.isEmpty(mBinding.etVciCarYears.getText())) {
            mViewModel.submitData().setCarYears(NumberUtil.convertToInt(mBinding.etVciCarYears.getText().toString()));
        } else {
            mViewModel.submitData().setCarYears(null);
        }
        if (!TextUtils.isEmpty(mBinding.tvOffice.getText())) {
            mViewModel.submitData().setImageIssuingAuthority(mBinding.tvOffice.getText().toString());
        } else {
            mViewModel.submitData().setImageIssuingAuthority("");
        }
        //提交
        mViewModel.save(this, mBinding.tvVciSubmit, mViewModel.submitData());
    }

    /**
     * 图片选择
     */
    private void showPictureDialog() {
        ChoosePictureDialog dialog = new ChoosePictureDialog(this, R.drawable.daoluyunshuzheng);
        dialog.setDialogClickCallBack(ids -> {
            if ("拍照".equals(ids)) {
                getTackPhoto();
            } else if ("从手机相册选择".equals(ids)) {
                getImage();
            }
        });
        dialog.show(getSupportFragmentManager(), "pic");
    }

    /**
     * 拍照
     */
    private void getTackPhoto() {
        PictureSelector.create(this)
                .openCamera(PictureMimeType.ofImage())
                .loadImageEngine(GlideEngine.createGlideEngine())
                .isCompress(true)//是否压缩
                .minimumCompressSize(4 * 1024)//小于4M不压缩
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    /**
     * 选择图片
     */
    private void getImage() {
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .loadImageEngine(GlideEngine.createGlideEngine())
                .selectionMode(PictureConfig.SINGLE)
                .isCompress(true)//是否压缩
                .minimumCompressSize(4 * 1024)//小于4M不压缩
                .maxSelectNum(1)//判断还能选多少张图片
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    private void chooseDump() {
        List<String> list = Arrays.asList("自卸", "非自卸");
        PickerHelper.with(this).getCommonPicker("是否自卸", list, (options1, options2, options3, v) -> {
            mViewModel.submitData().setIsDump(options1 == 0 ? 1 : 0);
            mBinding.tvVciIsDump.setText(list.get(options1));
        }).show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) return;
        if (requestCode == RequestCode.CODE_MAP) {
            AMapAddressEntity entity = AMapDialog.get(data);
            if (entity == null) return;
            mBinding.tvVciLocation.setText(String.format("%s%s%s%s",
                    entity.getProvince(),
                    entity.getCity(),
                    entity.getDistrict(), entity.getSnippet()));
            mBinding.etVciAddress.setVisibility(View.GONE);
            mBinding.etVciAddress.setText(entity.getSnippet());
            //设置提交定位数据
            mViewModel.submitData().setProvinceName(entity.getProvince());
            mViewModel.submitData().setProvinceNo(entity.getProvinceNo());
            mViewModel.submitData().setCityName(entity.getCity());
            mViewModel.submitData().setCityNo(entity.getCityNo());
            mViewModel.submitData().setDistrictName(entity.getDistrict());
            mViewModel.submitData().setDistrictNo(entity.getDistrictNo());
            mViewModel.submitData().setDetailAddress(entity.getSnippet());
            mViewModel.submitData().setLatitude(entity.getLatitude());
            mViewModel.submitData().setLongitude(entity.getLongitude());
            return;
        }
        String path = "";
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            List<LocalMedia> imageList = PictureSelector.obtainMultipleResult(data);
            if (imageList == null || imageList.size() == 0) return;
            //获取压缩图片
            path = imageList.get(0).getCompressPath();
        } else if (requestCode == PictureConfig.REQUEST_CAMERA && data != null) {
            path = data.getStringExtra("imagePath");
        }
        if (path != null) {
            mViewModel.uploadFile(this, new File(path));
        }
    }
}
